<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" :model="form" label-width="140px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="流水单号">
              <el-input v-model="form.orderSn" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="回款单号">
              <el-input v-model="form.repaymentSn" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="form.userPhone" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="医院名称">
              <hospitalListbth @childfun="childfun" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="状态">
              <el-select v-model="form.status" clearable placeholder="请选择">
                <el-option
                  v-for="item in minappStatusOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="退款时间">
              <el-date-picker
                v-model="form.dates"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报单类型">
              <el-select v-model="form.formType" clearable placeholder="请选择">
                <el-option label="全部" :value="null"></el-option>
                <el-option label="美美咖报单" :value="0"></el-option>
                <el-option label="传统报单" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <!-- <el-form-item> -->
            <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
            <el-button
              v-if="permissionJson.indexOf('AdminRepaymentProvider.exportRepaymentNegative') !=-1"
              plain
              type="primary"
              class="el-icon-download"
              @click="exportfun"
            >导出</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div class="listDiv">
      <!-- table列表 -->

      <el-table :data="tableData" class="tableData" style="width: 100%">
        <el-table-column type="index" label="序号" />
        <el-table-column prop="hospitalName" label="医院名称" />
        <el-table-column prop="formType" label="报单类型"></el-table-column>
        <el-table-column prop="paidRatio" label="回款比率" align="center" >
           <template slot-scope="scope">
                <span>{{ scope.row.paidRatio }}%</span>
           </template>
        </el-table-column>
        <el-table-column prop="repaymentSn" label="回款单号" />
        <el-table-column prop="paymentId" label="付款方式" />
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <span>{{ scope.row.status | RS }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="orderSn" label="流水单号" />
        <el-table-column prop="userName" label="客户姓名" />
        <el-table-column prop="userPhone" label="客户手机号">
          <template slot-scope="scope">
            <span>{{scope.row.userPhone | phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="receivableAmount" label="退款金额" />
        <el-table-column prop="receivedAmount" label="已抵扣金额" />
        <el-table-column prop="reviewAmount" label="审批中金额" />

        <el-table-column prop="surplusReceivableAmount" label="剩余抵扣金额" />
        <el-table-column prop="createdAt" label="退款日期 " />

        <el-table-column fixed="right" label="操作" width="100" align="center">
          <template slot-scope="scope">
            <span
              v-if="permissionJson.indexOf('AdminMmkHospitalPaidBackProvider.newMmkDrawbackPayment') !=-1"
            >
              <el-button
                v-if="scope.row.surplusReceivableAmount < 0 && scope.row.status==4"
                type="text"
                size="small"
                @click="toRoutes('paylist',scope.row.repaymentId)"
              >付款</el-button>
            </span>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { negativeList } from "@/api/refundedList";
import { hospitalList } from "@/api/financialBack";
import hospitalListbth from "@/components/hospitalList";
// // import { findHospitalTagsList } from '@/api/hospitalLabel'
import { exportfile } from "@/api/commjs/exprot";
export default {
  name: "RefundedList",
  components: {
    hospitalListbth
  },
  filters: {
    cardType: function(e) {
      return window.helper.cardType(e);
    },
    RS: function(e) {
      switch (e) {
        case "1":
          return "已回款";
        case "2":
          return "未回款";
        case "3":
          return "部分回款";
        case "4":
          return "未抵扣";
        case "5":
          return "已抵扣";
        case "6":
          return "抵扣中";
        case "7":
          return "已付款";
        default:
          return "暂无";
      }
    }
  },
  data() {
    return {
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      tableLoading: true,
      officeOption: [],
      statusOption: [
        {
          value: "",
          label: "全部"
        },
        {
          value: "0",
          label: "正常"
        },
        {
          value: "1",
          label: "停用"
        }
      ],
      isAppointedOption: [
        {
          value: "",
          label: "全部"
        },
        {
          value: "0",
          label: "不可预约"
        },
        {
          value: "1",
          label: "可以预约"
        }
      ],

      minappStatusOption: [
        {
          value: "",
          label: "全部"
        },
        {
          value: "4",
          label: "未抵扣"
        },
        {
          value: "5",
          label: "已抵扣"
        },
        {
          value: "6",
          label: "抵扣中"
        },
        {
          value: "7",
          label: "已付款"
        }
      ],
      hospitalOptions: [],
      form: {
          
        dates: [],
        repaymentSn: "",
        orderSn: "",
        userPhone: "",
        status: "",
        hospitalId: "",
        beginCreateDate: null,
        endCreateDate: null,
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 0,
      listForm: {
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  created() {
    this.getHospital();
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    // 导出
    exportfun() {
      exportfile(
        "com.mmk.reservation.api.AdminRepaymentProvider/1.0.0/exportRepaymentNegative.html",
        this.form
      );
    },
    childfun(res) {
      this.form.hospitalId = res.id + "";
    },
    // 按钮权限
    hasPermission(e) {
      return window.helper.hasPermission(e);
    },
    // 成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    // 医院名称
    getHospital() {
      //   hospitalList().then(res => {
      //     // console.log(res.data.data)
      //     if (res.data.data) {
      //       this.hospitalOptions = res.data.data.map(item => {
      //         return { value: String(item.id), label: item.name }
      //       })
      //     }
      //   })
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1;
      // console.log(this.form)
      if (this.form.dates) {
        this.form.beginCreateDate = this.form.dates[0];
        this.form.endCreateDate = this.form.dates[1];
      } else {
        this.form.beginCreateDate = null;
        this.form.endCreateDate = null;
      }
      this.getList(this.form);
    },
    // 路由跳转
    toRoutes(e, userId) {
      const route = { name: e, query: { userId: userId } };
      this.$router.push(route);
    },
    // 列表数据获取
    getList(e) {
      this.tableLoading = true;
      const datas = e;
      negativeList(datas)
        .then(res => {
          console.log(res.data);
          if (res.data.code == 0) {
            // console.log(res)
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },

    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    }
  }
};
</script>

<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
